import { _decorator, Component, Node, Label, Input, Scene, director, find } from 'cc';
import { heroManager } from './heroManager';
import { EnemyFactory } from './EnemyFactory';
import { GameConfig } from './config/GameConfig';
import { BoomMgr } from './BoomMgr';
const { ccclass, property } = _decorator;

@ccclass('GameOver')
export class GameOver extends Component {
    
    start() {
        
        // 监听重新开始和结束
        this.node.getChildByName('gameover').on(Input.EventType.TOUCH_END, this.over, this)
        this.node.getChildByName('again').on(Input.EventType.TOUCH_END, this.restart, this)

    }

    update(deltaTime: number) {
        
    }


    // 展示分数
    showOver(score: number) {
        
        // 显示分数
        this.node.getChildByName('score_show').getComponent(Label).string = score + ''

        this.node.active = true

    }

    // 重新开始
    restart() {
        // 重置参数: 分数 生命 游戏计时
        find('Canvas/enemys').removeAllChildren()
        
        find('Canvas/me1').getComponent(heroManager).restartGame()
        
        this.node.active = false

        // 重置游戏计时
        find('Canvas/enemy').getComponent(EnemyFactory).gameTime = 0

        // 炸弹清零
        // 增加炸弹计数
        GameConfig.boomBuffAmount = 0
        find('Canvas/syscontrol/bomb/boomAmount').getComponent(BoomMgr).setBoomAmount()

    }

    // 结束  回到首页
    over() {
        director.loadScene('first_page')
    }
}


